package com.dcivision.framework.web;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionMapping;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.bean.AbstractBaseObject;
import com.dcivision.framework.bean.EventMessageCode;

public class MaintEventCodeForm extends AbstractActionForm {
  
  public static final String REVISION = "$Revision: 1.1 $";
  
  private String eventType = null;
  private String messagePattern = null;
  private String msgCode = null;
  private String messageCode = null;

  public String getEventType() {
    return eventType;
  }

  public void setEventType(String eventType) {
    this.eventType = eventType;
  }

  public String getMessageCode() {
    return messageCode;
  }

  public void setMessageCode(String messageCode) {
    this.messageCode = messageCode;
  }

  public String getMessagePattern() {
    return messagePattern;
  }

  public void setMessagePattern(String messagePattern) {
    this.messagePattern = messagePattern;
  }

  public String getMsgCode() {
    return msgCode;
  }

  public void setMsgCode(String msgCode) {
    this.msgCode = msgCode;
  }

  public void setFormData(AbstractBaseObject baseObj) throws ApplicationException {
    EventMessageCode eventCode = (EventMessageCode)baseObj;
    this.setID(eventCode.getID().toString());
    this.setEventType(eventCode.getEventType());
    this.setMessagePattern(eventCode.getMessagePattern());
    this.setMessageCode(eventCode.getMessageCode());
    this.setMsgCode(eventCode.getMsgCode());
    this.setUpdateDate(formatTimestamp(eventCode.getUpdateDate()));
    this.setUpdaterID(TextUtility.formatIntegerObj(eventCode.getUpdaterID()));
    this.setUpdateCount(TextUtility.formatIntegerObj(eventCode.getUpdateCount()));
    this.setCreateDate(formatTimestamp(eventCode.getCreateDate()));
    this.setCreatorID(TextUtility.formatIntegerObj(eventCode.getCreatorID()));
  }

  public AbstractBaseObject getFormData() throws ApplicationException {
    EventMessageCode eventCode = new EventMessageCode();
    eventCode.setID(TextUtility.parseIntegerObj(this.getID()));
    eventCode.setEventType(this.getEventType());
    eventCode.setMessagePattern(this.getMessagePattern());
    eventCode.setMessageCode(this.getMessageCode());
    eventCode.setMsgCode(this.getMsgCode());
    eventCode.setUpdateDate(parseTimestamp(this.getUpdateDate()));
    eventCode.setUpdaterID(TextUtility.parseIntegerObj(this.getUpdaterID()));
    eventCode.setUpdateCount(TextUtility.parseIntegerObj(this.getUpdateCount()));
    eventCode.setCreateDate(parseTimestamp(this.getCreateDate()));
    eventCode.setCreatorID(TextUtility.parseIntegerObj(this.getCreatorID()));
    return eventCode;
  }
  
  public void reset(ActionMapping mapping, HttpServletRequest request) {
    super.reset(mapping, request);
    this.setID(null);
    this.setEventType(null);
    this.setMessagePattern(null);
    this.setMessageCode(null);
    this.setMsgCode(null);
    this.setUpdateDate(null);
    this.setUpdaterID(null);
    this.setUpdateCount(null);
    this.setCreateDate(null);
    this.setCreatorID(null);
  }
}
